<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>聊天练习</title>
    <style>
     ul{
         width: 200px;
         height: 100px;
         background-color: pink;
     }
     li{
    
         font-size: 20px;
         line-height: 100px;
     }
    input{
        width: 300px;
        height: 50px;
        background-color: skyblue;
        font-size: 16px;
        outline: none;
        border: none;
    }
    
    </style>
</head>
<body>
    
    <ul>
        <li>聊天消息：</li>
    </ul>

    <input type="text" placeholder="消息" class="txt">


    <script src="./lib/vue.js"></script>
    <script>
    // 根据选择器查找元素
    const $=selector=>document.querySelector(selector)
    $('.txt').addEventListener('keydown',e=>{
        if(e.keyCode===13){
            // 回车，发送消息
            const input = e.target.value
            const li = `<li>${input}</li>`
            $('ul').innerHTML+=li
            e.target.value=''
        }
    })
    
    
    </script>
</body>
</html>